package add;

import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
//按照代码顺序来
@FixMethodOrder(MethodSorters.JVM)
//跟着方法名来
//@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AddTest {
    private  static Add add =new Add();
    @Before
    public void  setUp() throws Exception {
        System.out.println("开始测试");
        add.claer();
    }
    @After
    public void tearDown() throws Exception {
        System.out.println("结束测试");
    }
    @Test
    @Category(A.class)
    public void ADD() {
        add.ADD(2,34);
        //assertEquals比较两个对象是否相等 用Equals来比较
        System.out.println("ADD开始测试");
        assertEquals(36,add.getRe());
        //asserThat allOf：所有条件必须都成立，测试才通过  ，结果在6和8之间
        System.out.println("测试变量是否大于指定值");
        //必须大于35 greaterThan方法
        assertThat(add.getRe(),greaterThan(35));
        //必须小于37 lessThan方法
        System.out.println("测试变量是否小于指定值");
        assertThat(add.getRe(),lessThan(37));
        //测试变量是否大于等于指定值 greaterThanOrEqualTo
        System.out.println("测试变量是否大于等于指定值");
        assertThat(add.getRe(),greaterThanOrEqualTo(36));
        //测试变量是否小于等于指定值 greaterThanOrEqualTo
        System.out.println("测试变量是否小于等于指定值");
        assertThat(add.getRe(),lessThanOrEqualTo(36));
        System.out.println("allOf：所有条件必须都成立，测试才通过  ，结果在6和8之间");
        assertThat(add.getRe(),allOf(greaterThan(35),lessThan(37)));
        //anyOf只要有一个条件成立，测试就通过
        System.out.println("anyof:||只要一个条件成立测试通过");
        assertThat(add.getRe(),anyOf(greaterThan(3),lessThan(222)));
        ////测试无论什么条件成立
        System.out.println("测试无论什么条件都成立");
        assertThat(add.getRe(),anything());
        //测试变量等于指定值 is
        System.out.println("测试变量等于指定值 is");
        assertThat(add.getRe(),is(36));
        //测试变量不等于指定值 is
        System.out.println("测试变量不等于指定值 not");
        assertThat(add.getRe(),not(46));
    }
    @Test
    @Category(A.class)
    public void sub() {
        String str = "Hello JAVA";
        String str1 =new String("Hello JAVA");
        String str2="hello java";
        String str3=" JAVA ";
        //如果目标 字符串包括测试字符串测试通过 containsString
        assertThat(str,containsString("Hello"));
        //如果目标字符串以测试字符串结尾泽通过 endsWith
        assertThat(str,endsWith("JAVA"));
        //如果目标字符串以测试字符串开头则通过 startsWinth
        assertThat(str,startsWith("Hello"));
        //如果目标字符串等于测试字符串则通过 equalTo
        assertThat(str,equalTo(str1));
        //忽略大小写与情况下等于 equalToIgnoringCase
        assertThat(str,equalToIgnoringCase(str2));
        //忽略头尾空格的情况下等于 equalToIgnoringWhiteSpace 忽略大大小写
        assertThat(str3,equalToIgnoringWhiteSpace("java"));
    }
    //timeout=int 超过多久未执行完成则失败
    //expected=""异常 抛出这个算成功
    @Test
    @Category(B.class)
    public void divtest(){
        String str =new String("1");
        assertEquals(str,add.str);
        double d=21.2;
        //误差多少
        assertThat(d,closeTo(21.0,0.2));

        assertThat(d,greaterThan(21.0));
    }
    @Test
    public void mul(){

    }
}